<h1><%= t :header, :scope => 'grids_list' %> </h1>

<table id="grids">
  <thead>
  <tr>
    <th><%=  t :name, :scope => %w{grids_list table columns} %></th>
    <th><%=  t :rows, :scope => %w{grids_list table columns} %></th>
    <th><%=  t :columns, :scope => %w{grids_list table columns} %></th>
  </tr>
  </thead>

  <tbody>
  <% @grids.each do |grid| %>
    <tr>
      <td><%= h grid.name %></td>
      <td><%= h grid.rows %></td>
      <td><%= h grid.columns %></td>
      <td><%= link_to t(current_user.account_type == 'operator' ? :edit : :view, :scope => %w{grids_list table rows}), :action => 'edit', :id => grid.id %></td>
      <% if current_user.account_type == 'operator' %>
        <td><%= link_to_function t(:delete, :scope => %w{grids_list table rows}), "confirmDelete('#{url_for(:action => 'destroy', :id => grid.id)}')" %></td>
      <% end %>
    </tr>
  <% end %>
  
  </tbody>

</table>

<script type="text/javascript">
  var url;
  function handleDelete() {
    var f = document.createElement('form');
    f.style.display = 'none';
    document.body.appendChild(f);
    f.method = 'POST';
    f.action = url;
      var m = document.createElement('input');
      m.setAttribute('type', 'hidden');
      m.setAttribute('name', '_method');
      m.setAttribute('value', 'delete');
      f.appendChild(m);
    f.submit();
  }

  function confirmDelete(url_p) {
    url = url_p;
    confirm('<%= t('grids_list.confirm_delete') %>', handleDelete);
  }
</script>